
public class Arg {

	private static int maxargs(Stm s) {
		if (s instanceof CompoundStm){
			CompoundStm cstm = (CompoundStm) s;
			return Math.max(maxargs(cstm.stm1), maxargs(cstm.stm2));
		}
		else if (s instanceof AssignStm){
			AssignStm astm = (AssignStm) s;
			return maxargs(astm.exp);
		}
		else if (s instanceof PrintStm){
			PrintStm pstm = (PrintStm) s;
			return Math.max(maxargs(pstm.exps), print_size(pstm.exps));
		}
		else{
			return 0;
		}
	}

	private static int maxargs(Exp e){
		if (e instanceof IdExp){
			return 1;
		}
		else if (e instanceof NumExp){
			return 1;
		}
		else if (e instanceof OpExp){
			OpExp oexp = (OpExp) e;
			return Math.max(maxargs(oexp.left), maxargs(oexp.right));
		}
		else if (e instanceof EseqExp){
			EseqExp eexp = (EseqExp) e;
			return Math.max(maxargs(eexp.stm), maxargs(eexp.exp));
		}
		else {
			return 0;
		}
	}
	private static int maxargs(ExpList el){
		if (el instanceof PairExpList){
			PairExpList plist = (PairExpList) el;
			return Math.max(maxargs(plist.head), maxargs(plist.tail));		
		}
		else if (el instanceof LastExpList){
			LastExpList llist = (LastExpList) el;
			return maxargs(llist.head);
		}
		else{
			return 0;
		}
	}
	
	private static int print_size(ExpList pel){
		if (pel instanceof PairExpList){
			PairExpList list = (PairExpList) pel;
			return 1 + print_size(list.tail);
		}
		else {
			return 1;
		}
	}
}